﻿<cfsilent>
	<cfscript>

		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		response = structNew();
		structInsert(response, "success", false, true);
		
		examId = event.getArg("EXID");
		newWeek = numberFormat(event.getArg("WK"), "0_");
		
		transaction {
						
			/* 加载考试任务 */
						
			sql = "UPDATE t_examtask SET wid = :examWeek WHERE task_exid = :taskExid ";
			
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="examWeek", value=newWeek, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="taskExid", value=examId, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );
		
			
			/* 数据密闭 */
			
			/* 如果已经保存了学生考试安排 则全部删除 */
			
			sql = "DELETE FROM t_student_exam WHERE task_exid = :taskExid";
			
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskExid", value=examId, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );
			
			/* 如果已经保存了场地占用 则全部删除 */
			sql = "DELETE FROM t_clsroom_timetable WHERE crtime_id IN (SELECT crtime_id FROM t_clsroom_forexam WHERE task_exid = :taskExid)";
							
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskExid", value=examId, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );
	

			sql = "DELETE FROM t_clsroom_forexam WHERE task_exid = :taskExid";
							
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskExid", value=examId, cfsqltype="cf_sql_char" );
			
			queryObj.execute( sql=sql );


			structInsert(response, "ExamID", examId, true);
			structInsert(response, "ExamWeek", newWeek, true);

			structInsert(response, "success", true, true);
			
		}
	


	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>